package com.wxq.blog.controller;

import com.wxq.blog.common.aop.LogAnnotation;
import com.wxq.blog.pojo.ArticleParam;
import com.wxq.blog.service.ArticleService;
import com.wxq.blog.vo.Result;
import com.wxq.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    @LogAnnotation(module = "文章",operation = "获取文章列表")//加入aop切面输出日志
    //查询所有文章
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }
    //查询最热文章
    @PostMapping("hot")
//    @Cache(expire = 5 * 60 * 1000,name = "hot_article")
    @LogAnnotation(module = "文章",operation = "获取最热文章列表")//加入aop切面输出日志
    public Result hotArticle() {
        int limit=5;
        return articleService.hotArticle(limit);
    }
    //查询最新文章
    @PostMapping("new")
    @LogAnnotation(module = "文章",operation = "获取最新文章列表")//加入aop切面输出日志
    public Result newArticles() {
        int limit=5;
        return articleService.newArticles(limit);
    }
    //查询归档文章
    @PostMapping("listArchives")
    @LogAnnotation(module = "文章",operation = "文章归档")//加入aop切面输出日志
    public Result listArchives() {
        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    @LogAnnotation(module = "文章",operation = "通过id查询获取文章")//加入aop切面输出日志
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
    //  @RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)；
    //  而最常用的使用请求体传参的无疑是POST请求了，所以使用@RequestBody接收数据时，一般都用POST方式进行提交。
    @PostMapping("publish")
    @LogAnnotation(module = "文章",operation = "提交文章")//加入aop切面输出日志
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }

}
